package com.zhu.gmallpublisher.service.impl;

import com.zhu.gmallpublisher.bean.TrafficDurPerSession;
import com.zhu.gmallpublisher.bean.TrafficPvPerSession;
import com.zhu.gmallpublisher.bean.TrafficSvCt;
import com.zhu.gmallpublisher.bean.TrafficUjRate;
import com.zhu.gmallpublisher.mapper.TrafficChannelStatsMapper;
import com.zhu.gmallpublisher.service.TrafficChannelStatsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigInteger;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 用户访问域服务层
 */
@Service
public class TrafficChannelStatsServiceImpl implements TrafficChannelStatsService {

    @Autowired
    private TrafficChannelStatsMapper trafficChannelStatsMapper;

    //  渠道日活
    @Override
    public Map getUvByCh(int date) {
        //hashMap resut;
        HashMap<String, BigInteger> resultMap = new HashMap<>();
        List<Map> mapList = trafficChannelStatsMapper.selectUvByCh(date);

        //变脸集合取出渠道
        for (Map map : mapList) {
            resultMap.put((String)map.get("ch"),(BigInteger)map.get("uv"));
        }
        return resultMap;
    }

    //渠道会话数
    @Override
    public List<TrafficSvCt> getSvCt(Integer date) {
        return trafficChannelStatsMapper.selectSvCt(date);
    }

    //平均会话页面数
    @Override
    public List<TrafficPvPerSession> getPvPerSession(Integer date) {
        return trafficChannelStatsMapper.selectPvPerSession(date);
    }

    //平均会话范访问时长
    @Override
    public List<TrafficDurPerSession> getDurPerSession(Integer date) {
        return trafficChannelStatsMapper.selectDurPerSession(date);
    }

    //平均跳出率
    @Override
    public List<TrafficUjRate> getUjRate(Integer date) {
        return trafficChannelStatsMapper.selectUjRateCount(date);
    }


}
